<%--
  Created by IntelliJ IDEA.
  User: zzy
  Date: 2025/8/31
  Time: 21:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>发票管理系统</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="assets/css/admin.css">
    <link rel="stylesheet" href="assets/css/app.css">
    <script type="text/javascript">

    </script>
</head>
<body data-type="generalComponents">
<header class="am-topbar am-topbar-inverse admin-header">
    <div class="am-collapse am-topbar-collapse" id="topbar-collapse">
        <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list tpl-header-list">
            <li class="am-dropdown" data-am-dropdown data-am-dropdown-toggle>
                <a class="am-dropdown-toggle tpl-header-list-link" href="javascript:">
                    <span class="tpl-header-list-user-nick">我不是厨神</span><span
                        class="tpl-header-list-user-ico"> <img
                        src="assets/img/user04.png"></span>
                </a>
                <ul class="am-dropdown-content">
                    <li><a href="index.jsp"><span class="am-icon-power-off"></span> 退出</a></li>
                </ul>
            </li>
        </ul>
    </div>
    <style>
        .ele-dot-text {
            width: 45px;
            display: inline-block;
            margin-left: 20px;
        }

        .ele-dot-status {

            width: 8px;
            height: 8px;
            display: inline-block;
            border-radius: 50%;
            line-height: 10px;
        }

        .ele-dot-status-success {
            background: #52c41a;
        }

        .ele-dot-status-error {
            background: #ff4d4f;
        }

        .ele-dot-status-info {
            background: #1890ff;
        }
    </style>
</header>
<div class="tpl-page-container tpl-page-header-fixed">
    <div class="tpl-left-nav tpl-left-nav-hover">
        <div class="tpl-left-nav-list">
            <ul class="tpl-left-nav-menu">
                <li class="tpl-left-nav-item">
                    <a href="javascript:" class="nav-link tpl-left-nav-link-list active">
                        <i class="am-icon-table"></i>
                        <span>发票管理</span>
                        <i class="am-icon-angle-right tpl-left-nav-more-ico am-fr am-margin-right tpl-left-nav-more-ico-rotate"></i>
                    </a>
                    <ul class="tpl-left-nav-sub-menu" style="display:block">
                        <li>
                            <a href="invoice-list.jsp" class="active">
                                <i class="am-icon-angle-right"></i>
                                <span>发票总览管理</span>
                            </a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <div class="tpl-content-wrapper">
        <div class="tpl-content-page-title" style="margin-bottom: 4px;">
            发票管理
        </div>
        <div class="am-g" style="height: 100px;">
            <div class="am-u-sm-6" style="padding-left: 0;">
                <div class="tpl-portlet-components">
                    <div class="tpl-block " >
                        <div id="idInvoice" class="am-g tpl-amazeui-form">
                            <div class="am-u-sm-12 am-u-md-3">
                                <div class="am-u-sm-12" style="text-align: center;font-weight: bold;">
                                    <div>可开票金额</div>
                                    <div id="idInvoicableAmount" style="color: red;font-size: 20px;"></div>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-1">
                                <div class="am-u-sm-12" style="text-align: center;font-weight: bold;">
                                    <div>=</div>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-3">
                                <div class="am-u-sm-12" style="text-align: center;font-weight: bold;">
                                    <div STYLE="    white-space: nowrap;">总计可开票金额</div>
                                    <div id="idTotalInvoice" style="color: red;font-size: 20px;"></div>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-1">
                                <div class="am-u-sm-12" style="text-align: center;font-weight: bold;">
                                    <div>-</div>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-3">
                                <div class="am-u-sm-12" style="text-align: center;font-weight: bold;">
                                    <div>历史已开票</div>
                                    <div id="idHistoryInvoice" style="color: red;font-size: 20px;"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <a href="invoice-open.jsp" class="am-btn am-btn-primary"
                       style="margin-bottom: 10px;margin-left: 40px;margin-top: 8px;">去开票</a>
                </div>
            </div>
            <div class="am-u-sm-6">
                <div class="tpl-portlet-components">
                    <div class="tpl-block " >
                        <div></div>
                        <div class="am-g tpl-amazeui-form">
                            <div class="am-u-sm-12 am-u-md-6">
                                <div class="am-u-sm-12">
                                    <span style="font-size: 18px;font-weight: bold;">发票抬头及地址信息</span>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-6">
                                <div class="am-u-sm-12">
                                    <a href="invoice-info-manage.jsp" class="am-btn am-btn-default"
                                       style="float: right;">编辑</a>
                                </div>
                            </div>
                        </div>
                        <div class="am-g tpl-amazeui-form" style="font-size: 14px;color: #666;margin-bottom: 5px;">
                            <div class="am-u-sm-12 am-u-md-6">
                                <div class="am-u-sm-12">
                                    <span style="color: #333;">抬头（默认）：</span> <span id="m-u-sm-12-title"></span>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-6">
                                <div class="am-u-sm-12">
                                    <span style="color: #333;">税号：</span> <span id="am-u-sm-12-taxNo"></span>
                                </div>
                            </div>
                        </div>
                        <div class="am-g tpl-amazeui-form" style="font-size: 14px;color: #666;margin-bottom: 5px;">
                            <div class="am-u-sm-12 am-u-md-6">
                                <div class="am-u-sm-12">
                                    <span style="color: #333;">邮寄地址（默认）：</span> <span
                                        id="am-u-sm-12-addressDetail"></span>
                                </div>
                            </div>
                        </div>
                        <div class="am-g tpl-amazeui-form" style="font-size: 14px;color: #666;">
                            <div class="am-u-sm-12 am-u-md-6">
                                <div class="am-u-sm-12">
                                    <span style="color: #333;">电子邮箱：</span> <span
                                        id="am-u-sm-12-emailDetail"></span>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 搜索条件 -->
        <div class="am-g" style="height: 100px;">
            <div class="am-u-sm-12" style="padding-left: 0;">
                <div class="tpl-portlet-components">
                    <div class="tpl-block " id="resultDiv">
                        <div class="am-g tpl-amazeui-form">

                            <div class="am-u-sm-6 am-u-md-3">
                                <div class="am-input-group am-input-group-sm-date-1">
                                                <span class="am-input-group-btn">
                                                    <span
                                                            style="font-size: 14px;margin-right: 8px;margin-left: 8px">发票申请日期</span>
                                                </span>
                                    <input type="text" id="am-form-field-date-id"
                                           class="am-form-field-date am-datepicker-input" data-am-datepicker
                                           placeholder="&nbsp;&nbsp;请选择日期"
                                           style="border: 1px solid #c2cad8;width: 68%;border-radius: 3px;">
                                </div>
                            </div>

                            <div class="am-u-sm-6 am-u-md-3">
                                <div class="am-input-group am-input-group-sm-sort-1">
                                                <span class="am-input-group-btn">
                                                    <span style="font-size: 14px;margin-right: 8px;margin-left: 8px">发票抬头</span>
                                                </span>
                                    <input type="text" id="am-form-field-head" class="am-form-field-head"
                                           placeholder="&nbsp;&nbsp;请输入发票抬头"
                                           style="border: 1px solid #c2cad8;width: 68%;border-radius: 3px;">
                                </div>
                            </div>
                            <div class="am-u-sm-6 am-u-md-3" style="margin-left: -10px;">
                                <div class="am-input-group am-input-group-sm-money">
                                                <span class="am-input-group-btn">
                                                    <span style="font-size: 14px;margin-right: 8px;margin-left: 8px">发票金额</span>
                                                </span>
                                    <input type="text" class="am-form-field1" placeholder="&nbsp;&nbsp;最低金额(万)"
                                           style="border: 1px solid #c2cad8;width: 32%;border-radius: 3px;">
                                    <div class="am-form-field"
                                         style="width: 0; border-radius: 3px;border: none;margin-left: 10px;">~
                                    </div>
                                    <input type="text" class="am-form-field2" placeholder="&nbsp;&nbsp;最高金额(万)"
                                           style="border: 1px solid #c2cad8;width: 32%;border-radius: 3px;margin-left: 20px;">
                                </div>
                            </div>
                            <div class="am-g">
                                <div class="am-u-sm-6 am-u-md-3">
                                    <div class="am-input-group am-input-group-sm">
                                                    <span class="am-input-group-btn">
                                                        <span
                                                                style="font-size: 14px;margin-right: 8px;margin-left: 8px">处理状态</span>
                                                    </span>
                                        <div class="am-btn-group am-btn-group-sm status-type">
                                            <button type="button" id="all" class="am-btn am-btn-primary "
                                                    data-status="">全部
                                            </button>
                                            <%--                                                <button type="button" class="am-btn am-btn-default" value="申请中">申请中</button>--%>
                                            <button type="button" id="Invoiced" class="am-btn am-btn-default"
                                                    data-status="A">已开票
                                            </button>
                                            <button type="button" id="Obsolete" class="am-btn am-btn-default "
                                                    data-status="B">已作废
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 发票列表 -->
        <div class="tpl-portlet-components">
            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-title">发票申请时间</th>
                                <th class="table-author am-hide-sm-only">发票抬头</th>
                                <th class="table-author am-hide-sm-only">发票金额（元）</th>
                                <th class="table-date am-hide-sm-only">上链地址</th>
                                <th class="table-date am-hide-sm-only">处理状态</th>
                                <th class="table-set">操作</th>
                            </tr>
                            </thead>


                            <tbody id="doc-modal-list-body">
                            <%--                            <tr data-id="2">--%>
                            <%--                                <td class="am-hide-sm-only">2021-12-31 12：12：12</td>--%>
                            <%--                                <td class="am-hide-sm-only">百度科技有限公司</td>--%>
                            <%--                                <td class="am-hide-sm-only">1,000,000.00</td>--%>
                            <%--                                <td class="am-hide-sm-only">F64A3FA774552D72</td>--%>
                            <%--                                <td class="am-hide-sm-only">--%>
                            <%--                                            <span class="ele-dot-status ele-dot-status-success"></span>--%>
                            <%--                                                    <span class="ele-dot-text"> 已开票</span>--%>
                            <%--                                <td>--%>
                            <%--                                    <div class="am-btn-toolbar">--%>
                            <%--                                        <div class="am-btn-group am-btn-group-xs">--%>
                            <%--                                            <a href="invoice-detail.jsp"><span class="am-text-secondary"--%>
                            <%--                                                                                style="cursor:pointer"><span></span>--%>
                            <%--                                                            详情</span></a>--%>
                            <%--                                            <span class="am-text-secondary am-icon"--%>
                            <%--                                                  style="cursor:pointer"><span></span>--%>
                            <%--                                                        退票</span>--%>
                            <%--                                        </div>--%>
                            <%--                                    </div>--%>
                            <%--                                </td>--%>
                            <%--                            </tr>--%>
                            <%--                            <tr data-id="2">--%>
                            <%--                                <td class="am-hide-sm-only">2021-12-31 12：12：12</td>--%>
                            <%--                                <td class="am-hide-sm-only">百度科技有限公司</td>--%>
                            <%--                                <td class="am-hide-sm-only">1,000,000.00</td>--%>
                            <%--                                <td class="am-hide-sm-only">F64A3FA774552D72</td>--%>
                            <%--                                <td class="am-hide-sm-only">--%>
                            <%--                                            <span class="ele-dot-status ele-dot-status-error"></span>--%>
                            <%--                                                    <span class="ele-dot-text">已作废</span>--%>
                            <%--                                <td>--%>
                            <%--                                    <div class="am-btn-toolbar">--%>
                            <%--                                        <div class="am-btn-group am-btn-group-xs">--%>
                            <%--                                            <a href="invoice-detail.jsp"><span class="am-text-secondary"--%>
                            <%--                                                                                style="cursor:pointer"><span></span>--%>
                            <%--                                                            详情</span></a>--%>
                            <%--                                        </div>--%>
                            <%--                                    </div>--%>
                            <%--                                </td>--%>
                            <%--                            </tr>--%>
                            <%--                            <tr data-id="2">--%>
                            <%--                                <td class="am-hide-sm-only">2021-12-31 12：12：12</td>--%>
                            <%--                                <td class="am-hide-sm-only">百度科技有限公司</td>--%>
                            <%--                                <td class="am-hide-sm-only">1,000,000.00</td>--%>
                            <%--                                <td class="am-hide-sm-only">F64A3FA774552D72</td>--%>
                            <%--                                <td class="am-hide-sm-only">--%>
                            <%--                                            <span class="ele-dot-status ele-dot-status-error"></span>--%>
                            <%--                                                    <span class="ele-dot-text">已作废</span>--%>
                            <%--                                <td>--%>
                            <%--                                    <div class="am-btn-toolbar">--%>
                            <%--                                        <div class="am-btn-group am-btn-group-xs">--%>
                            <%--                                            <a href="invoice-detail.jsp"><span class="am-text-secondary"--%>
                            <%--                                                                                style="cursor:pointer"><span></span>--%>
                            <%--                                                            详情</span></a>--%>
                            <%--                                        </div>--%>
                            <%--                                    </div>--%>
                            <%--                                </td>--%>
                            <%--                            </tr>--%>
                            <%--                            <tr data-id="2">--%>
                            <%--                                <td class="am-hide-sm-only">2021-12-31 12：12：12</td>--%>
                            <%--                                <td class="am-hide-sm-only">百度科技有限公司</td>--%>
                            <%--                                <td class="am-hide-sm-only">1,000,000.00</td>--%>
                            <%--                                <td class="am-hide-sm-only">F64A3FA774552D72</td>--%>
                            <%--                                <td class="am-hide-sm-only">--%>
                            <%--                                            <span class="ele-dot-status ele-dot-status-error"></span>--%>
                            <%--                                                    <span class="ele-dot-text">已作废</span>--%>
                            <%--                                <td>--%>
                            <%--                                    <div class="am-btn-toolbar">--%>
                            <%--                                        <div class="am-btn-group am-btn-group-xs">--%>
                            <%--                                            <a href="invoice-detail.jsp"><span class="am-text-secondary"--%>
                            <%--                                                                                style="cursor:pointer"><span></span>--%>
                            <%--                                                            详情</span></a>--%>
                            <%--                                        </div>--%>
                            <%--                                    </div>--%>
                            <%--                                </td>--%>
                            <%--                            </tr>--%>
                            <%--                            <tr data-id="2">--%>
                            <%--                                <td class="am-hide-sm-only">2021-12-31 12：12：12</td>--%>
                            <%--                                <td class="am-hide-sm-only">百度科技有限公司</td>--%>
                            <%--                                <td class="am-hide-sm-only">1,000,000.00</td>--%>
                            <%--                                <td class="am-hide-sm-only">F64A3FA774552D72</td>--%>
                            <%--                                <td class="am-hide-sm-only">--%>
                            <%--                                            <span class="ele-dot-status ele-dot-status-success"></span>--%>
                            <%--                                                    <span class="ele-dot-text">已开票</span>--%>
                            <%--                                <td>--%>
                            <%--                                    <div class="am-btn-toolbar">--%>
                            <%--                                        <div class="am-btn-group am-btn-group-xs">--%>
                            <%--                                            <a href="invoice-detail.jsp"><span class="am-text-secondary"--%>
                            <%--                                                                                style="cursor:pointer"><span></span>--%>
                            <%--                                                            详情</span></a>--%>
                            <%--                                            <span class="am-text-secondary am-icon"--%>
                            <%--                                                  style="cursor:pointer"><span></span>--%>
                            <%--                                                        退票</span>--%>
                            <%--                                        </div>--%>
                            <%--                                    </div>--%>
                            <%--                                </td>--%>
                            <%--                            </tr>--%>

                            </tbody>

                            <tfoot id="doc-modal-list-foot"></tfoot>


                        </table>
<%--                        <div class="am-cf">--%>
<%--                            <div class="am-fr">--%>
<%--                                <ul class="am-pagination tpl-pagination">--%>
<%--                                    <li class="am-disabled"><a href="#">«</a></li>--%>
<%--                                    <li class="am-active"><a href="#">1</a></li>--%>
<%--                                    <li><a href="#">2</a></li>--%>
<%--                                    <li><a href="#">3</a></li>--%>
<%--                                    <li><a href="#">4</a></li>--%>
<%--                                    <li><a href="#">5</a></li>--%>
<%--                                    <li><a href="#">»</a></li>--%>
<%--                                </ul>--%>
<%--                            </div>--%>
<%--                        </div>--%>
                        <hr>
                    </form>
                </div>
                <!-- 退票二次确认弹出框 -->
                <div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
                    <div class="am-modal-dialog" style="font-size: 16px;">
                        <div class="am-modal-hd">提示</div>
                        <div class="am-modal-bd">
                            将进行退票，是否继续？
                        </div>
                        <div class="am-modal-footer">
                            <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                            <span class="am-modal-btn" data-am-modal-confirm>确定</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="assets/js/jquery-1.8.3.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<script src="assets/js/app.js"></script>
<script src="tools.js"></script>
<script>


    $(document).ready(function () {
        show(1, "", "", "", 0, 99999999999);

        amount()

        emailInfo()
    })


    function emailInfo() {

        $.ajax({
            url: "fenye/getDefaultShowEmail",
            type: "post",
            success: function (response) {

                $("#m-u-sm-12-title").text(response.title);

                $("#am-u-sm-12-taxNo").text(response.taxNo);

                $("#am-u-sm-12-addressDetail").text(response.addressDetail);

                $("#am-u-sm-12-emailDetail").text(response.emailDetail);
            }
        })
    }


    function amount() {
        $.ajax({
            url: "fenye/queryInvoiceTotal",
            type: "post",
            success: function (response) {

                var c = getTotalInvoiceAmount(response)
                // 3.1 渲染“总计可开票金额”（response.totalInvoiceAmount 是数字类型）
                $("#idTotalInvoice").text(c + "元");
                // 3.2 渲染“历史已开票金额”（response.taoHistoricalInvoice 是字符串类型）
                $("#idHistoryInvoice").text(response.taoHistoricalInvoice + "元");
                // 3.3 渲染“可开票金额”（response.canInvoiceAmount 是字符串类型）
                $("#idInvoicableAmount").text(response.canInvoiceAmount + "元");
            }
        })
    }


    // 新增：监听日期选择器的change事件（选择日期后自动筛选）
    $(document).on("change", "#am-form-field-date-id", function () {
        // 1. 获取所有筛选条件（日期、种类、金额、状态）
        var creaTime = $(this).val(); // 日期（已按yyyy-MM-dd格式）
        var title = $("#am-form-field-head").val(); // 发票种类
        var min = $("input[class=am-form-field1]").val().trim().replace(/[^0-9]/g, ""); // 最低金额
        var max = $("input[class=am-form-field2]").val().trim().replace(/[^0-9]/g, ""); // 最高金额
        var statusText = $(".status-type button.am-btn-primary").text().trim(); // 当前选中状态（全部/已开票/已作废）

        var Status = (statusText === "已开票" ? "A" : (statusText === "已作废" +
        "" ? "B" : "")); // 状态映射

        // 2. 调用show函数，从第1页加载筛选结果（携带所有条件）
        show(1, creaTime, title, Status, min, max);
    });


    $('.status-type').on('click', 'button', function () {
        // 1. 切换按钮样式（当前点击的按钮变蓝，其他变灰）
        $(this).addClass('am-btn-primary').siblings().removeClass('am-btn-primary');

        // 2. 获取当前选中的状态值（从按钮的data-status属性，如“已开票”对应“A”）
        var Status = $(this).data("status"); // 全部→""，已开票→"A"，已作废→"B"

        // 3. 获取当前其他筛选条件（日期、发票种类、金额范围），避免筛选条件丢失
        var createTime = $("#am-form-field-date-id").val(); // 日期（如用户选择的2024-10-01）
        // createTime = new Date(createTime);
        // createTime = createTime.toISOString().split('T')[0];

        var title = $("#am-form-field-head").val(); // 发票种类（如“增值税专用发票”）
        var min = $("input[class='am-form-field1']").val().trim().replace(/[^0-9]/g, ""); // 最低金额
        var max = $("input[class='am-form-field2']").val().trim().replace(/[^0-9]/g, ""); // 最高金额

        // 4. 关键：调用show函数，发起筛选请求（默认回到第1页）
        // 传递参数：页码1 + 日期 + 种类 + 状态（A/B/空） + 金额范围
        show(1, createTime, title, Status, min, max);
    })

    // （可选）调试：确认参数是否正确传递

    $(document).on("blur", "input[type='text']", function () {
        var createTime = $("#am-form-field-date-id").val();
        // createTime = new Date(createTime);
        //  createTime = createTime.toISOString().split('T')[0];

        // input[class='am-form-field-date']
        console.log(createTime + "日期值")

        var title = $("#am-form-field-head").val();//保持当前发票种类筛选

        var min = $("input[class='am-form-field1']").val().trim().replace(/[^0-9]/g, "");
        var max = $("input[class='am-form-field2']").val().trim().replace(/[^0-9]/g, "");


        var Status = $(".status-type .am-btn-primary").data("status");

        show(1, createTime, title, Status, min, max)

    })

    // 分页按钮点击事件（携带所有筛选条件）
    $(document).on("click", "#doc-modal-list-foot input[type='button']", function () {
        var indexpage = $(this).attr("alt"); // 获取目标页码
        var createTime = $("#am-form-field-date-id").val(); // 保持当前日期筛选
        // createTime = new Date(createTime);
        // createTime = createTime.toISOString().split('T')[0];
        console.log(createTime + "日期值")


        var title = $("#am-form-field-head").val(); // 保持当前发票种类筛选

        var min = $("input[class='am-form-field1']").val().trim().replace(/[^0-9]/g, ""); // 保持当前金额min筛选
        var max = $("input[class='am-form-field2']").val().trim().replace(/[^0-9]/g, ""); // 保持当前金额max筛选

        // var statusText = $(".status-type button.am-btn-primary").text().trim(); // 保持当前状态筛选
        var Status = $(".status-type .am-btn-primary").data("status");

        show(indexpage, createTime, title, Status, min, max); // 调用show函数并传递所有参数
    });


    //getListPage传的InvoicingRecordShow 没有id属性
    function show(indexpage, createTime, title, Status, min, max) {

        //1.创建加载后，发送异步请求，获得分页数据：
        $.get("fenye/getListPage", {
            "indexpage": indexpage,
            "createTime": createTime,
            "title": title,
            "status": Status,
            "min": min, "max": max
        }, function (ph) {
            // console.log("Received response:", ph);
            console.log(JSON.stringify(ph))
            //1.获得ph里的集合，循环遍历到tbody
            $("#doc-modal-list-body").empty();
            for (var i = 0; i < ph.listIndex.length; i++) {

                var obj = ph.listIndex[i];
                // console.log("原始createTime:", obj.createTime);
                $("            <tr>\n" +
                    "                <td>" + formatDate(obj.createTime) + "</td>\n" +
                    "                <td>" + obj.title + "</td>\n" +
                    "                <td>" + obj.amount + "</td>\n" +
                    "                <td>" + obj.upLinkAddress + "</td>\n" +
                    "                <td>" +
                    (obj.status === "B" ?
                            // 状态B：已作废 → 红色点
                            "<span class='ele-dot-status ele-dot-status-error'></span><span class='ele-dot-text'>已作废</span>" :
                            (obj.status === "A" ?
                                    // 状态A：已作废 → 红色点
                                    "<span class='ele-dot-status ele-dot-status-success'></span><span class='ele-dot-text'>已开票</span>" :
                                    // 其他状态：已开票 → 绿色点
                                    "<span class='ele-dot-status ele-dot-status-error'></span><span class='ele-dot-text'>未开票</span>"
                            )
                    ) +
                    "                <td>\n" +
                    "                    <a href='invoice-detail.jsp?upLinkAddress=" + (obj.upLinkAddress || "") + "'> 详情</a> " + // 详情链接不变
                    //当你把一个 “对象”（比如循环里的obj，包含id/title/amount等信息）拼接到 URL 里时，JS 会自动把对象转成字符串
                    "                    " + (obj.status === "B" ? "" : "<a  class='refund-btn' alt='" + (obj.upLinkAddress || "") + "'>退票</a>") + " " + // 退票链接加class
                    "                </td>\n" +
                    "            </tr>").appendTo("#doc-modal-list-body");
            }

            //2.获得ph里的属性，动态添加到tfoot
            $("#doc-modal-list-foot").empty();
            console.log("Setting up pagination controls. Current page:", ph.pageIndex, "Total pages:", ph.pageCount);
            if (ph.pageIndex != 1) {
                $("<input type='button' value='首页' alt='1'/>").appendTo("#doc-modal-list-foot");
                $("<input type='button' value='上一页' alt='" + (ph.pageIndex - 1) + "'/>").appendTo("#doc-modal-list-foot");
            }

            for (var i = 1; i <= ph.pageCount; i++) {
                $("<input type='button' value='" + i + "' alt='" + i + "'/>").appendTo("#doc-modal-list-foot");
            }

            if (ph.pageIndex != ph.pageCount) {
                $("<input type='button' value='下一页' alt='" + (ph.pageIndex + 1) + "'/>").appendTo("#doc-modal-list-foot");
                $("<input type='button' value='尾页' alt='" + ph.pageCount + "'/>").appendTo("#doc-modal-list-foot");
            }
            $("<b>第" + ph.pageIndex + "页/共" + ph.pageCount + "页</b>").appendTo("#doc-modal-list-foot");
        });
    }


    //
    // // 退票二次确认
    // $(function () {
    //     //状态按钮样式切换
    //     $('.status-type').find('button').on('click', function () {
    //         let statusTypeBtnArr = $('.status-type').find('button');
    //         for (let i = 0; i < statusTypeBtnArr.length; i++) {
    //             statusTypeBtnArr.eq(i).removeClass('am-btn-primary');
    //         }
    //         $(this).addClass('am-btn-primary');
    //     });
    //     $('#doc-modal-list').find('.am-icon').add('#doc-confirm-toggle').on('click', function () {
    //         $('#my-confirm').modal({
    //             relatedTarget: this,
    //             onConfirm: function (options) {
    //                 //点击确认调用函数
    //                 alert("点击了确认");
    //             },
    //             onCancel: function () {
    //                 //点击取消调用函数
    //                 alert("点击了取消")
    //             }
    //         });
    //     });
    // });


    // 退票二次确认（修复后）
    $(function () {
        // 1. 状态按钮样式切换（原逻辑不变，保留）
        $('.status-type').find('button').on('click', function () {

            let statusTypeBtnArr = $('.status-type').find('button');
            for (let i = 0; i < statusTypeBtnArr.length; i++) {
                statusTypeBtnArr.eq(i).removeClass('am-btn-primary');
            }
            $(this).addClass('am-btn-primary');
        });

        // 2. 核心：给退票链接（.refund-btn）绑定事件委托（动态元素生效）
        $(document).on('click', '#doc-modal-list-body .refund-btn', function () {
            // 获取当前退票的发票ID（需确保<tr>有data-id，之前已加）
            const upLinkAddress = $(this).attr("alt");

            // 触发二次确认弹框
            $('#my-confirm').modal({

                relatedTarget: this,
                onConfirm: function (options) {

                    $.get("fenye/backInvoice", {upLinkAddress: upLinkAddress}, function (judge) {
                            if (judge) {
                                alert("退票成功");
                                location.reload();
                            } else {
                                alert("退票失败");
                                location.reload();
                            }
                        }

                        // 后续可添加：调用refundInvoice(invoiceId)接口
                    )
                },
                onCancel: function () {
                    console.log("已取消退票");
                }
            })
        })
    })




</script>
</body>
</html>
